package operation;


import book.Book;
import book.BookList;

import java.util.Scanner;

public class Delete implements IOperation{
    public void work(BookList bookList){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的书籍:");
        String name = scanner.nextLine();

        int cur = bookList.getUsedSize();
        int index = -1;
        for (int i = 0; i < cur; i++) {
            Book book = bookList.getBookList(i);
            if(book.getName().equals(name)) {
                index = i;
                break;
            }
        }
        if(index == -1){
            System.out.println("没有你要删除的书!");
            return;
        }
        for (int i = index; i < cur-1; i++) {
            Book book = bookList.getBookList(i+1);
            bookList.setBookList(i,book);
        }
        bookList.setUsedSize(cur-1);
    }
}
